package com.xy.server.entity;

import com.xy.server.util.ServerUtil;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class Profile {

    public String profile_file_name;

    BufferedImage profile;

    int averageBrightness;

    private Map<Integer,BufferedImage> bufferedMap = new HashMap<Integer, BufferedImage>();

    public Map<Integer, BufferedImage> getBufferedMap() {
        return bufferedMap;
    }

    public void setBufferedMap(Map<Integer, BufferedImage> bufferedMap) {
        this.bufferedMap = bufferedMap;
    }

    public int getAverageBrightness() {
        return averageBrightness;
    }

    public void setAverageBrightness(int averageBrightness) {
        this.averageBrightness = averageBrightness;
    }

    public BufferedImage getProfile() {
        return profile;
    }

    public void setProfile(BufferedImage profile) {
        this.profile = profile;
    }
    public Profile(
            File profile_file,
            String origin_file_name,
            String emotion,
            int red_count,
            int green_count,
            int blue_count,
            int pixel_count,
            long create_time
    ) throws Exception {
        this.profile_file_name = profile_file_name;

        profile = ImageIO.read(profile_file);

        Color averageColorPng = new Color(red_count * 1.0f / pixel_count / 255,
                green_count * 1.0f / pixel_count / 255,
                blue_count * 1.0f / pixel_count / 255);

        averageBrightness = (int) ((0.2125 * averageColorPng.getRed()) + (0.7154 * averageColorPng.getGreen()) + (0.072 * averageColorPng.getBlue()));
    }


}
